package Java.view.game.dian21;

import javafx.animation.TranslateTransition;
import javafx.util.Duration;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;


/**
 * 扑克牌面板
 */
public class Tool {
    //设置电脑停止要牌的临界点
    private static final int STOP_SCORE = 18;
    private static final String PLAYER_LOSE = "你输啦！";
    private static final String COMPUTER_LOSE = "庄家输啦！";
    private static final String DOG_FALL = "平局";

    public Tool() {

    }

    public static void move(Poker poker, Point from, Point to) {
        // 创建TranslateTransition动画对象
        TranslateTransition transition = new TranslateTransition(Duration.millis(500), poker);
        // 设置动画的起始位置
        transition.setFromX(from.x);
        transition.setFromY(from.y);
        // 设置动画的结束位置
        transition.setToX(to.x);
        transition.setToY(to.y);
        // 启动动画
        transition.play();
    }

    /**
     * 判断电脑是否还要牌
     *
     * @return 布尔值
     */
    public static boolean computerNeed(ArrayList<Poker> list) {
        int sum = 0;
        for (Poker poker : list) {
            sum += poker.getValue();
        }
        return sum < STOP_SCORE;
    }

    /**
     * 判断是否超过21点
     *
     * @return 布尔值
     */
     public static boolean isOver(ArrayList<Poker> list){
         int sum = 0;
         for (Poker poker : list) {
             sum += poker.getValue();
         }
         return sum > 21;
     }

    /**
     *  判断输赢
     *
     * @return 谁胜利了
     */
     public static String isWin(ArrayList<Poker> playerList, ArrayList<Poker> computerList){
         int playerSum = 0;
         int computerSum = 0;
         for (Poker poker : playerList) {
             playerSum += poker.getValue();
         }
         for (Poker poker : computerList) {
             computerSum += poker.getValue();
         }
         if(playerSum == computerSum){
             return DOG_FALL;
         }else if(playerSum < computerSum){
             return PLAYER_LOSE;
         }else{
             return COMPUTER_LOSE;
         }
     }
}